package com.axend.aerosense.room.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.axend.aerosense.base.bean.RoomTypeBean;
import com.axend.aerosense.base.bean.TimeZoneBean;
import com.axend.aerosense.base.fragment.MvvmBaseFragment;
import com.axend.aerosense.base.impl.ILoadDataResult;
import com.axend.aerosense.base.impl.ILoginStatusChanged;
import com.axend.aerosense.base.impl.IOperationDetailResult;
import com.axend.aerosense.base.impl.IOperationResult;
import com.axend.aerosense.base.livedatabus.LiveDatabus;
import com.axend.aerosense.base.storage.MmkvHelper;
import com.axend.aerosense.base.utils.SystemUtil;
import com.axend.aerosense.base.viewmodel.BaseViewModelFactroy;
import com.axend.aerosense.common.bean.FunctionRoomEnum;
import com.axend.aerosense.common.bean.PersonSelectItemBean;
import com.axend.aerosense.common.bean.RadarBean;
import com.axend.aerosense.common.bean.RadarType;
import com.axend.aerosense.common.bean.UserInfo;
import com.axend.aerosense.common.bean.WardSelectItemBean;
import com.axend.aerosense.common.config.Gobal;
import com.axend.aerosense.common.config.Gobal.ERROR_CODE;
import com.axend.aerosense.common.router.RouterActivityPath;
import com.axend.aerosense.common.ui.CustomSettingItemView;
import com.axend.aerosense.common.ui.CustomTipsDialog;
import com.axend.aerosense.room.BR;
import com.axend.aerosense.room.R;
import com.axend.aerosense.room.databinding.RoomFragmentSettingBinding;
import com.axend.aerosense.room.entity.FunctionSetInfo;
import com.axend.aerosense.room.entity.RoomEmergencyBean;
import com.axend.aerosense.room.entity.RoomItemBean;
import com.axend.aerosense.room.entity.RoomSetttingInfoBean;
import com.axend.aerosense.room.entity.RoomSetttingParentBean;
import com.axend.aerosense.room.entity.RoomTypeChangeBean;
import com.axend.aerosense.room.entity.RoomTypeEnum;
import com.axend.aerosense.room.entity.RoomVipSetBean;
import com.axend.aerosense.room.entity.RoomWardBean;
import com.axend.aerosense.room.ui.activity.PeoplePickerActivity;
import com.axend.aerosense.room.ui.activity.RoomAddActivity;
import com.axend.aerosense.room.ui.activity.RoomDeviceListActivity;
import com.axend.aerosense.room.ui.activity.RoomSceneLearnActivity;
import com.axend.aerosense.room.ui.activity.RoomSettingFunctionActivity;
import com.axend.aerosense.room.ui.activity.RoomVipFunActivity;
import com.axend.aerosense.room.ui.activity.SaveModelActivity;
import com.axend.aerosense.room.ui.adapter.RoomDeviceCardAdapter;
import com.axend.aerosense.room.ui.provider.VipFunctionRepository;
import com.axend.aerosense.room.viewmodel.RoomSettingInfoViewModel;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.Utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 房间监护人和被监护人,以及房间信息设定界面
 */
public class RoomSettingFragment extends MvvmBaseFragment<RoomFragmentSettingBinding, RoomSettingInfoViewModel>
        implements ILoginStatusChanged, ILoadDataResult<RoomSetttingParentBean> {

    public static final int REQUEST_PERSON = 1212;
    public static final int REQUEST_WARD = 1213;
    public static final int REQUEST_VIP_SET_CODE = 888;
    private static final int DELETE_ROOM_CODE = 33;
    // 界面打开模式: true 为创建模式, false为修改模式, 默认修改模式
    private boolean createMode = false;
    private RoomTypeBean roomTypeInfo = null;
    private RoomItemBean editRoom;
    private FunctionSetInfo functionSetInfo;
    private RoomSetttingInfoBean roomSettingBean;
    private boolean roomNameUserChanged = false;
    private View.OnClickListener onPersonClickListener, onWardClickListener;
    private long clickTime = 0;
    private RoomDeviceCardAdapter roomDeviceCardAdapter;
    private List<RadarBean> radarInfoList;
    private int studyTime;

    private Map<FunctionRoomEnum, DataBean> functionViewMap;
    private Map<FunctionRoomEnum, List<RoomVipSetBean>> functionDadaMap;
    private CustomTipsDialog vipTipsDialog;

    public static RoomSettingFragment getInstance() {
        RoomSettingFragment fragment = new RoomSettingFragment();
//        Bundle bundle = new Bundle();
//        bundle.putString(ROOM_TYPE, roomType);
//        fragment.setArguments(bundle);   //设置参数
        return fragment;
    }

    public static String OPEN_PARAM_ROOMINFO = "roomInfo";
    public static String OPEN_PARAM_ROOMTYPEINFO = "roomTypeInfo";

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView();
    }

    @Override
    protected void initParameters() {
        super.initParameters();
        Bundle bundle = getArguments();
        if (null != bundle) {
            editRoom = (RoomItemBean) bundle.getSerializable(OPEN_PARAM_ROOMINFO); // 如果不为空则为修改模式
            roomTypeInfo = (RoomTypeBean) bundle.getSerializable(OPEN_PARAM_ROOMTYPEINFO);// 如果不为空则为创建模式
        }
        if (null == editRoom) {
            createMode = true;
        } else {
            createMode = false;
        }

    }

    private void initView() {
        if (null != roomTypeInfo) {
//            viewDataBinding.roomType.setText(roomTypeInfo.getRoomName());
            viewModel.roomType.setValue(roomTypeInfo);
            // 创建房间时, 默认给予房间类型名称
//            viewDataBinding.roomName.setText(roomTypeInfo.getRoomName().replace(" ", ""));
            //不去空格
//            viewDataBinding.roomName.setText(roomTypeInfo.getRoomName());
            viewModel.roomName.setValue(roomTypeInfo.getRoomName());
        }
        if (createMode) {
            // 创建房间时,隐藏VIP设定
            viewDataBinding.roomVipFunList.setVisibility(View.GONE);
            // 创建模式不显示设备卡片
            viewDataBinding.roomDevicesCard.setVisibility(View.GONE);
            // 创建模式下不显示自动学习
            viewModel.isShowAutoLearn.setValue(false);
        }

        viewModel.isCreateMode.setValue(createMode);

        roomDeviceCardAdapter = new RoomDeviceCardAdapter();
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false);
        viewDataBinding.roomRvDeviceList.setLayoutManager(layoutManager);
        viewDataBinding.roomRvDeviceList.setAdapter(roomDeviceCardAdapter);

        //顶部设备卡片点击事件
        viewDataBinding.roomDevicesCardView.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), RoomDeviceListActivity.class);
            intent.putExtra(RoomDeviceListActivity.ROOM_UUID, editRoom.getRoomUuid());
            intent.putExtra(RoomDeviceListActivity.ROOM_NAME, editRoom.getRoomName());
            intent.putExtra(RoomDeviceListActivity.PAGER_FLAG, RoomDeviceListActivity.DEVICES_LIST_PAGER);
            startActivity(intent);
        });

        viewDataBinding.roomName.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), SaveModelActivity.class);
            intent.putExtra(SaveModelActivity.OPEN_MODE_ROOM_NAME, viewModel.roomName.getValue());
            if (!createMode) {
                intent.putExtra(SaveModelActivity.OPEN_MODE_ROOM_ID, editRoom.getRoomUuid());
            }
            intent.putExtra(SaveModelActivity.OPEN_TYPE, SaveModelActivity.OPEN_TYPE_SET_NAME);
            getActivity().startActivityForResult(intent, SaveModelActivity.REQUEST_CODE_SET_NAME);
        });

        viewDataBinding.roomType.setOnClickListener(v -> {
            /*编辑模式下不允许修改房间类型*/
            if (createMode) {
                Intent intent = new Intent(getActivity(), SaveModelActivity.class);
                intent.putExtra(SaveModelActivity.OPEN_MODE_ROOM_TYPE, viewModel.roomType.getValue());
                intent.putExtra(SaveModelActivity.OPEN_TYPE, SaveModelActivity.OPEN_TYPE_SET_ROOM_TYPE);
                getActivity().startActivityForResult(intent, SaveModelActivity.REQUEST_CODE_SET_TYPE);
            }
        });

        //自动学习
        viewDataBinding.roomLayout.setOnClickListener(v -> {
            Intent intent = new Intent(getActivity(), RoomSceneLearnActivity.class);
            intent.putExtra(RoomSceneLearnActivity.RADAR_ID, getAssureRadarId());
            intent.putExtra(RoomSceneLearnActivity.STUDY_TIME, studyTime);
            startActivity(intent);
        });

        onPersonClickListener = v -> {
            Intent intent = new Intent(getActivity(), PeoplePickerActivity.class);
            Bundle bundle = new Bundle();
            // 联系人界面
            bundle.putInt(Gobal.CLASS_KEY.OPEN_TYPE_KEY, PeoplePickerActivity.OPEN_TYPE_PERSON);
            intent.putExtra(Gobal.CLASS_KEY.OPEN_TYPE_KEY, PeoplePickerActivity.OPEN_TYPE_PERSON);
            // 选择模式
            intent.putExtra(Gobal.CLASS_KEY.SELECT_MODE_KEY, true);
            if (null != viewModel.personSelected.getValue()) {
                // 传入已经选择的联系人
                intent.putExtra(Gobal.CLASS_KEY.OBJECT_UID_KEY, viewModel.personSelected.getValue().getEmergencyUuid());
            }

            getActivity().startActivityForResult(intent, RoomSettingFragment.REQUEST_PERSON, bundle);
        };

        viewDataBinding.roomConnectPersonName.setOnClickListener(onPersonClickListener);

        onWardClickListener = v -> {
            Intent intent = new Intent(getActivity(), PeoplePickerActivity.class);
            Bundle bundle = new Bundle();
            // 监护人界面
            intent.putExtra(Gobal.CLASS_KEY.OPEN_TYPE_KEY, PeoplePickerActivity.OPEN_TYPE_WARD);
            bundle.putInt(Gobal.CLASS_KEY.OPEN_TYPE_KEY, PeoplePickerActivity.OPEN_TYPE_WARD);
            // 选择模式
            intent.putExtra(Gobal.CLASS_KEY.SELECT_MODE_KEY, true);
            if (null != viewModel.wardSelected.getValue()) {
                // 传入已经选择的受监护人
                intent.putExtra(Gobal.CLASS_KEY.OBJECT_UID_KEY, viewModel.wardSelected.getValue().getWardUuid());
            }

            getActivity().startActivityForResult(intent, RoomSettingFragment.REQUEST_WARD, bundle);
        };

        viewDataBinding.roomProtectPerson.setOnClickListener(onWardClickListener);

//        viewDataBinding.roomPosition.setOnClickListener(v->{
//            Intent intent  = new Intent(this.getActivity(), TimeZonePieckerActivity.class);
//            if(null != editRoom){
//                TimeZoneBean timeZoneBean = TimeZoneBean.format(getActivity(), editRoom.getTimeZone());
//                intent.putExtra(TimeZonePieckerActivity.PARAM_KEY, timeZoneBean);
//            }
//            getActivity().startActivityForResult(intent, TimeZonePieckerActivity.REQUEST_CODE);
//
//        });

        viewDataBinding.roomCreate.setOnClickListener(v -> {
            long currentTime = System.currentTimeMillis();
            if (currentTime - clickTime < 2000) {
                return;
            }
            clickTime = currentTime;
            if (!createMode) {
                CustomTipsDialog dialog = new CustomTipsDialog(getActivity(), getString(R.string.room_check_delete));
                dialog.setOnClickBottomListener(new CustomTipsDialog.OnClickBottomListener() {

                    @Override
                    public void onPositiveClick() {
                        dialog.dismiss();
                        // 此处删除
                        viewModel.deletRoom(getActivity(), new IOperationDetailResult<String>() {
                            @Override
                            public void onSuccess(String s) {
                                ToastUtils.showShort(R.string.common_success);
                                LiveDatabus.getInstance().with(Gobal.EVENT_KEY.REFESH_ROOM, Integer.class).postValue(DELETE_ROOM_CODE);
                                getActivity().setResult(RoomAddActivity.RESPONSE_CODE_CLOSE);
                                getActivity().finish();

                            }

                            @Override
                            public void onFail(int errCode, String message) {
                                dialog.dismiss();
                                if (ERROR_CODE.ERR_LOGIN == errCode) {
                                    ToastUtils.showShort(R.string.common_login_first);
                                    ARouter.getInstance().build(RouterActivityPath.Login.PAGE_LOGIN_HOME).withBoolean("jumpMainPage", true).greenChannel().navigation();

                                } else if (errCode == ERROR_CODE.ERR_DELETE) {
                                    CustomTipsDialog dialog = new CustomTipsDialog(getActivity(), getString(R.string.room_delete_tips));
                                    dialog.setOnClickBottomListener(new CustomTipsDialog.OnClickBottomListener() {

                                        @Override
                                        public void onPositiveClick() {
                                            dialog.dismiss();
                                        }

                                        @Override
                                        public void onNegtiveClick() {
                                            dialog.dismiss();
                                        }
                                    });
                                    dialog.show();
                                } else {
                                    ToastUtils.showShort(message);
                                }
                            }

                        });
                    }

                    @Override
                    public void onNegtiveClick() {
                        dialog.dismiss();
                    }
                });
                dialog.show();
            } else {
                viewModel.createRoom(getActivity(), new IOperationResult() {
                    @Override
                    public void onSuccess() {
                        LiveDatabus.getInstance().with(Gobal.EVENT_KEY.REFESH_ROOM, Integer.class).postValue(1);
                        ToastUtils.showShort(Utils.getApp().getString(R.string.common_success));
                        getActivity().finish();
                    }

                    @Override
                    public void onFail() {

                    }
                });
            }

        });
        if (!createMode) {
            setLoadSir(viewDataBinding.roomContentView);
            showLoading();
            viewModel.onLoad();
        }

        //离家模式
        viewDataBinding.roomModeSwitch.setOnClickListener(v -> {
            if (null != editRoom) {
                boolean leaveHomeState = viewModel.offMode.getValue();
                viewModel.updateLeaveHome(getActivity(), new IOperationResult() {

                    @Override
                    public void onSuccess() {
                        viewModel.offMode.setValue(!leaveHomeState);
                    }

                    @Override
                    public void onFail() {
                        viewModel.offMode.setValue(leaveHomeState);
                    }
                });
            }
        });

        //摔倒报警开关
        viewDataBinding.roomFallSwitch.setOnClickListener(v -> {
            boolean switchChecked = viewDataBinding.roomFallSwitch.isChecked();
            viewModel.updateFallAlert(getActivity(), switchChecked, new IOperationResult() {
                @Override
                public void onSuccess() {
                }

                @Override
                public void onFail() {
                    viewDataBinding.roomFallSwitch.setChecked(!switchChecked);
                }
            });
        });

        //原地静止
        viewDataBinding.roomMotionlessAlert.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getMotionlessAlert();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_MOTIONLESS_ALERT, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.MOTIONLESS_ALERT);
            }
        });

        //卫浴滞留
        viewDataBinding.roomBathroomDetention.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getToiletStop();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_TOILET_DETENTION, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.EXTENDED_TOILETING_ALERT);
            }
        });

        //用餐分析
        viewDataBinding.roomMealAnalysis.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getHaveMeals();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_MEAL_ANALYSIS, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.NUTRITION_ALERT);
            }
        });

        //起夜未归
        viewDataBinding.roomNightNoBack.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getNightRiseNoReturn();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_NIGHT_NO_BACK, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.WANDERING_ALERT_NIGHT);
            }
        });

        //熬夜提醒(作息异常)
        viewDataBinding.roomRegularLifestyle.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getWorkAndRest();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_REGULAR_LIFESTYLE, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.BEDTIME_NOTIFICATION);
            }
        });

        //频繁起夜
        viewDataBinding.roomNightUpAnalysis.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getNightRise();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_NIGHT_UP_ANALYSIS, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.FREQUENT_NIGHT_ACTIVITY);
            }
        });

//        //睡眠质量分析
//        viewDataBinding.roomSleepQualityAnalysis.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
//            List<RoomVipSetBean> beans = functionSetInfo.getSleepAnalysis();
//            if (checkDada(beans)){
//                toVipActivity(RoomVipFunActivity.FLAG_SLEEP_QUALITY_ANALYSIS, beans.get(0));
//            }
//        });

        //外出未归
        viewDataBinding.roomOutNoBack.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getEgressNoReturn();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_OUT_NO_BACK, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.WANDERING_ALERT_DAY);
            }
        });

        //频繁如厕
        viewDataBinding.roomBathroomUseAnalysis.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getToiletAnalysis();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_BATHROOM_USE_ANALYSIS, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.FREQUENT_TOILETING_AT_NIGHT);
            }
        });

        //卧床不起
        viewDataBinding.roomSleepTimeout.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getSleepOvertime();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_SLEEP_TIMEOUT, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.OVERSLEEPING_ALERT);
            }
        });

        //久坐分析
        viewDataBinding.roomSedentaryAnalysis.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getContinuitySit();
            List<RoomVipSetBean> beans2 = functionSetInfo.getAccumulateSit();
            if (checkDada(beans) && checkDada(beans2)) {
                //toVipActivity(RoomVipFunActivity.FLAG_SEDENTARY_ANALYSIS, beans.get(0));
                toFunctionSettingPager(beans.get(0), beans2.get(0), FunctionRoomEnum.SEDENTARY_NOTIFICATION);
            }
        });

        //行动能力分析
        viewDataBinding.roomTrendAnalysis.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getTrendAnalysis();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_TREND_ANALYSIS, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.MOBILITY_ANALYSIS);
            }
        });

        //心跳/呼吸骤停告警
        viewDataBinding.roomNoVitalSignals.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getNoVitalSignals();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_NO_VITAL_SIGNALS, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.NO_VITAL_SIGNALS);
            }
        });

        //离床告警
        viewDataBinding.roomBedExitWarning.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getBedExitWarning();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_BED_EXIT_WARNING, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.BED_EXIT_WARNING);
            }
        });

        //作息异常
        viewDataBinding.roomAbnormalSleep.setOnClickListener((CustomSettingItemView.OnClickListener) view -> {
            List<RoomVipSetBean> beans = functionSetInfo.getAbnormalSleep();
            if (checkDada(beans)) {
                //toVipActivity(RoomVipFunActivity.FLAG_ABNORMAL_SLEEP, beans.get(0));
                toFunctionSettingPager(beans.get(0), FunctionRoomEnum.ABNORMAL_SLEEP);
            }
        });
        LiveDatabus.getInstance()
                .with(Gobal.EVENT_KEY.REFESH_ROOM, Integer.class)
                .observe(getViewLifecycleOwner(), new Observer<Integer>() {
                    @Override
                    public void onChanged(Integer integer) {
                        if (integer != DELETE_ROOM_CODE)
                            onRetryBtnClick();
                    }
                });
    }

    private void toFunctionSettingPager(RoomVipSetBean setBean, FunctionRoomEnum functionRoomEnum) {
        toFunctionSettingPager(setBean, null, functionRoomEnum);
    }

    /**
     * 跳转到房间VIP设置页面（新的）
     */
    private void toFunctionSettingPager(RoomVipSetBean setBean,
                                        RoomVipSetBean setBean2, FunctionRoomEnum functionRoomEnum) {
        UserInfo userInfo = MmkvHelper.getInstance()
                .getMmkv()
                .decodeParcelable(Gobal.SAVE_KEY.USR_INFO, UserInfo.class);
        //如果不是VIP，提示用户去开通VIP
        if (userInfo.userVipState != 1) {
            showVipTipsDialog();
            return;
        }

        String roomId = roomSettingBean.getRoomUuid();
        int roomType = roomSettingBean.getRoomType();
        setBean.setRoomUuid(roomId);
        setBean.setRoomType(roomType);

        Bundle bundle = new Bundle();
        bundle.putSerializable(RoomSettingFunctionFragment.KEY_FUNCTION_ENUM, functionRoomEnum);
        bundle.putSerializable(RoomSettingFunctionFragment.KEY_VIP_SET_BEAN, setBean);
        if (null != setBean2) {
            setBean2.setRoomUuid(roomId);
            setBean2.setRoomType(roomType);
            bundle.putSerializable(RoomSettingFunctionFragment.KEY_ACCUMULATIVE_SETTING, setBean2);
        }
        Intent intent = new Intent(getActivity(), RoomSettingFunctionActivity.class);
        intent.putExtras(bundle);
        startActivity(intent);

    }

//    private void initFunctionViewMap(){
//        functionViewMap = new HashMap<>();
//        functionViewMap.put(FunctionRoomEnum.SURVEILLANCE_MODE, viewDataBinding.roomModeInfo);
//        functionViewMap.put(FunctionRoomEnum.FALL_ALERT, viewDataBinding.roomFallInfo);
//        functionViewMap.put(FunctionRoomEnum.OVERSLEEPING_ALERT, viewDataBinding.roomSleepTimeout);
//        functionViewMap.put(FunctionRoomEnum.FREQUENT_NIGHT_ACTIVITY, viewDataBinding.roomNightUpAnalysis);
//        functionViewMap.put(FunctionRoomEnum.WANDERING_ALERT_NIGHT, viewDataBinding.roomNightNoBack);
//        functionViewMap.put(FunctionRoomEnum.WANDERING_ALERT_DAY, viewDataBinding.roomOutNoBack);
//        functionViewMap.put(FunctionRoomEnum.SEDENTARY_NOTIFICATION, viewDataBinding.roomSedentaryAnalysis);
//        functionViewMap.put(FunctionRoomEnum.BEDTIME_NOTIFICATION, viewDataBinding.roomRegularLifestyle);
//        functionViewMap.put(FunctionRoomEnum.NUTRITION_ALERT, viewDataBinding.roomMealAnalysis);
//        functionViewMap.put(FunctionRoomEnum.EXTENDED_TOILETING_ALERT, viewDataBinding.roomBathroomDetention);
//        functionViewMap.put(FunctionRoomEnum.FREQUENT_TOILETING_AT_NIGHT, viewDataBinding.roomBathroomUseAnalysis);
//        functionViewMap.put(FunctionRoomEnum.MOTIONLESS_ALERT, viewDataBinding.roomMotionlessAlert);
//        functionViewMap.put(FunctionRoomEnum.MOBILITY_ANALYSIS, viewDataBinding.roomTrendAnalysis);
//        functionViewMap.put(FunctionRoomEnum.NO_VITAL_SIGNALS, viewDataBinding.roomNoVitalSignals);
//        functionViewMap.put(FunctionRoomEnum.BED_EXIT_WARNING, viewDataBinding.roomBedExitWarning);
//        functionViewMap.put(FunctionRoomEnum.ABNORMAL_SLEEP, viewDataBinding.roomAbnormalSleep);
//    }

    private void initFunctionViewMap(FunctionSetInfo setInfo) {
        functionViewMap = new HashMap<>();
        functionViewMap.put(FunctionRoomEnum.SURVEILLANCE_MODE, new DataBean(viewDataBinding.roomModeInfo));
        functionViewMap.put(FunctionRoomEnum.FALL_ALERT, new DataBean(viewDataBinding.roomFallInfo));
        functionViewMap.put(FunctionRoomEnum.OVERSLEEPING_ALERT, new DataBean(viewDataBinding.roomSleepTimeout, setInfo.getSleepOvertime()));
        functionViewMap.put(FunctionRoomEnum.FREQUENT_NIGHT_ACTIVITY, new DataBean(viewDataBinding.roomNightUpAnalysis, setInfo.getNightRise()));
        functionViewMap.put(FunctionRoomEnum.WANDERING_ALERT_NIGHT, new DataBean(viewDataBinding.roomNightNoBack, setInfo.getNightRiseNoReturn()));
        functionViewMap.put(FunctionRoomEnum.WANDERING_ALERT_DAY, new DataBean(viewDataBinding.roomOutNoBack, setInfo.getEgressNoReturn()));
        functionViewMap.put(FunctionRoomEnum.SEDENTARY_NOTIFICATION, new DataBean(viewDataBinding.roomSedentaryAnalysis, setInfo.getContinuitySit(), setInfo.getAccumulateSit()));
        functionViewMap.put(FunctionRoomEnum.BEDTIME_NOTIFICATION, new DataBean(viewDataBinding.roomRegularLifestyle, setInfo.getWorkAndRest()));
        functionViewMap.put(FunctionRoomEnum.NUTRITION_ALERT, new DataBean(viewDataBinding.roomMealAnalysis, setInfo.getHaveMeals()));
        functionViewMap.put(FunctionRoomEnum.EXTENDED_TOILETING_ALERT, new DataBean(viewDataBinding.roomBathroomDetention, setInfo.getToiletStop()));
        functionViewMap.put(FunctionRoomEnum.FREQUENT_TOILETING_AT_NIGHT, new DataBean(viewDataBinding.roomBathroomUseAnalysis, setInfo.getToiletAnalysis()));
        functionViewMap.put(FunctionRoomEnum.MOTIONLESS_ALERT, new DataBean(viewDataBinding.roomMotionlessAlert, setInfo.getMotionlessAlert()));
        functionViewMap.put(FunctionRoomEnum.MOBILITY_ANALYSIS, new DataBean(viewDataBinding.roomTrendAnalysis, setInfo.getTrendAnalysis()));
        functionViewMap.put(FunctionRoomEnum.NO_VITAL_SIGNALS, new DataBean(viewDataBinding.roomNoVitalSignals, setInfo.getNoVitalSignals()));
        functionViewMap.put(FunctionRoomEnum.BED_EXIT_WARNING, new DataBean(viewDataBinding.roomBedExitWarning, setInfo.getBedExitWarning()));
        functionViewMap.put(FunctionRoomEnum.ABNORMAL_SLEEP, new DataBean(viewDataBinding.roomAbnormalSleep, setInfo.getAbnormalSleep()));

    }

    private void initFunctionDataMap() {
        functionDadaMap = new HashMap<>();
        functionDadaMap.put(FunctionRoomEnum.SURVEILLANCE_MODE, null);
        functionDadaMap.put(FunctionRoomEnum.FALL_ALERT, null);
        functionDadaMap.put(FunctionRoomEnum.OVERSLEEPING_ALERT, functionSetInfo.getSleepOvertime());
        functionDadaMap.put(FunctionRoomEnum.FREQUENT_NIGHT_ACTIVITY, functionSetInfo.getNightRise());
        functionDadaMap.put(FunctionRoomEnum.WANDERING_ALERT_NIGHT, functionSetInfo.getNightRiseNoReturn());
        functionDadaMap.put(FunctionRoomEnum.WANDERING_ALERT_DAY, functionSetInfo.getEgressNoReturn());
        functionDadaMap.put(FunctionRoomEnum.SEDENTARY_NOTIFICATION, functionSetInfo.getContinuitySit());
        functionDadaMap.put(FunctionRoomEnum.BEDTIME_NOTIFICATION, functionSetInfo.getWorkAndRest());
        functionDadaMap.put(FunctionRoomEnum.NUTRITION_ALERT, functionSetInfo.getHaveMeals());
        functionDadaMap.put(FunctionRoomEnum.EXTENDED_TOILETING_ALERT, functionSetInfo.getToiletStop());
        functionDadaMap.put(FunctionRoomEnum.FREQUENT_TOILETING_AT_NIGHT, functionSetInfo.getToiletAnalysis());
        functionDadaMap.put(FunctionRoomEnum.MOTIONLESS_ALERT, functionSetInfo.getMotionlessAlert());
        functionDadaMap.put(FunctionRoomEnum.MOBILITY_ANALYSIS, functionSetInfo.getTrendAnalysis());
        functionDadaMap.put(FunctionRoomEnum.NO_VITAL_SIGNALS, functionSetInfo.getNoVitalSignals());
        functionDadaMap.put(FunctionRoomEnum.BED_EXIT_WARNING, functionSetInfo.getBedExitWarning());
        functionDadaMap.put(FunctionRoomEnum.ABNORMAL_SLEEP, functionSetInfo.getAbnormalSleep());
    }

    /**
     * 获取当前房间设置功能列表
     */
    private List<FunctionRoomEnum> getFunctionList(RoomTypeEnum roomTypeEnum, List<RadarType> radarTypeList) {
        Set<FunctionRoomEnum> roomFunctionList =
                VipFunctionRepository.getRoomFunctionList(roomTypeEnum, radarTypeList);
        LogUtils.d("功能列表", roomFunctionList);
        return new ArrayList<>(roomFunctionList);
    }

    /**
     * 初始化功能列表
     */
    private void initVipFunction() {
        RoomTypeEnum roomTypeEnum = RoomTypeEnum.get(roomSettingBean.getRoomType());
        List<RadarType> radarTypeList = new ArrayList<>();
        for (RadarBean radarBean : radarInfoList) {
            radarTypeList.add(radarBean.getType());
        }
        List<FunctionRoomEnum> functionList = getFunctionList(roomTypeEnum, radarTypeList);
        for (FunctionRoomEnum functionEnum : functionViewMap.keySet()) {
            boolean contains = functionList.contains(functionEnum);
            DataBean dataBean = functionViewMap.get(functionEnum);
            if(null == dataBean){
                return;
            }
            View view = dataBean.view;
            if (view instanceof ConstraintLayout) {
                view.setVisibility(contains ? View.VISIBLE : View.GONE);
            } else if (view instanceof CustomSettingItemView) {
                CustomSettingItemView itemView = (CustomSettingItemView) view;
                if(null != dataBean.setBean && null != dataBean.setBean.get(0) && dataBean.setBean.get(0).serviceFunctionSwitch != 1){
                    contains = false;
                }
                //如果包含，就显示，否则隐藏
                itemView.setIsShow(contains);
                //设置右边开关的状态
                boolean state = false;
                if (checkDada(dataBean.setBean)) {
                    state = dataBean.setBean.get(0).getFunctionSwitch() == 1;
                    if (functionEnum == FunctionRoomEnum.SEDENTARY_NOTIFICATION && checkDada(dataBean.accumulateBean)) {
                        state = state || dataBean.accumulateBean.get(0).getFunctionSwitch() == 1;
                    }
                }
                itemView.setRightText(state ? getString(R.string.common_vip_open) : getString(R.string.common_vip_close));
            }
        }
    }

    /**
     * 检查是否有功能设置数据
     */
    private boolean checkDada(List<RoomVipSetBean> beans) {
        return beans != null && beans.size() > 0;
    }

    private String getAssureRadarId() {
        if (radarInfoList == null || radarInfoList.size() <= 0) return null;
        String radarId = null;
        for (RadarBean bean : radarInfoList) {
            if (bean.getType() == RadarType.ASSURE) {
                radarId = bean.getRadarUuid();
            }
        }
        return radarId;
    }


    private void toVipActivity(int flag, RoomVipSetBean roomVipSetBean) {
        UserInfo userInfo = MmkvHelper.getInstance().getMmkv().decodeParcelable(Gobal.SAVE_KEY.USR_INFO, UserInfo.class);
        //是否跳转到开通vip
        if (userInfo.userVipState == 1) {
            //在这里顺便把房间信息传过去
            roomVipSetBean.setRoomUuid(editRoom.getRoomUuid());
            roomVipSetBean.setRoomType(roomSettingBean.getRoomType());
            LogUtils.d("toVipActivity", roomVipSetBean.toString());

            Intent intent = new Intent(getActivity(), RoomVipFunActivity.class);
            intent.putExtra(RoomVipFunActivity.FLAG, flag);
            intent.putExtra(RoomVipFunActivity.FLAG_SETTINGS_DATA, roomVipSetBean);

            if (flag == RoomVipFunActivity.FLAG_SEDENTARY_ANALYSIS) {
                List<RoomVipSetBean> beans = functionSetInfo.getAccumulateSit();
                if (beans != null && beans.size() > 0) {
                    intent.putExtra(RoomVipFunActivity.FLAG_ACCUMULATE_SIT, beans.get(0));
                }
            }
            startActivityForResult(intent, REQUEST_VIP_SET_CODE);

        } else {
            CustomTipsDialog dialog = new CustomTipsDialog(getContext(), getString(R.string.common_vip_service_tips));
            dialog.setPositiveText(R.string.common_to_vip_service);
            dialog.setOnClickBottomListener(new CustomTipsDialog.OnClickBottomListener() {
                @Override
                public void onPositiveClick() {
                    dialog.dismiss();
                    ARouter.getInstance().build(RouterActivityPath.Pay.PAGE_PAY_HOME).navigation();
                }

                @Override
                public void onNegtiveClick() {
                    dialog.dismiss();
                }
            });
            dialog.show();
        }
    }

    /**
     * 显示开通VIP提示弹窗
     */
    private void showVipTipsDialog() {
        if (null == vipTipsDialog) {
            vipTipsDialog = new CustomTipsDialog(getContext(), getString(R.string.common_vip_service_tips));
            vipTipsDialog.setPositiveText(R.string.common_to_vip_service);
            vipTipsDialog.setOnClickBottomListener(new CustomTipsDialog.OnClickBottomListener() {
                @Override
                public void onPositiveClick() {
                    dismissVipTipsDialog();
                    ARouter.getInstance().build(RouterActivityPath.Pay.PAGE_PAY_HOME).navigation();
                }

                @Override
                public void onNegtiveClick() {
                    dismissVipTipsDialog();
                }
            });
        }
        vipTipsDialog.show();
    }

    private void dismissVipTipsDialog() {
        if (null == vipTipsDialog) {
            return;
        }
        vipTipsDialog.dismiss();
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == REQUEST_VIP_SET_CODE) {
            //更新数据
            //viewModel.onLoad();

        } else if (requestCode == SaveModelActivity.REQUEST_CODE_SET_TYPE) {
            if (null == data) {
                return;
            }
            RoomTypeBean typeBean = (RoomTypeBean) data.getSerializableExtra(SaveModelActivity.OPEN_MODE_ROOM_TYPE);
            if (null == typeBean) {
                return;
            }
            if (!createMode) {
                // 编辑模式,提交后改变
                TimeZoneBean timeZoneBean = SystemUtil.getTimeZone();
                RoomTypeChangeBean roomTypeBean = new RoomTypeChangeBean(editRoom.getRoomUuid(), typeBean.getRoomType(), typeBean.getRoomName(), viewModel.roomName.getValue(), timeZoneBean.getRoomTimeZone(), timeZoneBean.getRoomTimeZoneArea());
                viewModel.setRoomType(getActivity(), roomTypeBean, new IOperationDetailResult<RoomSetttingParentBean>() {

                    @Override
                    public void onSuccess(RoomSetttingParentBean bean) {
//                                viewModel.setRoomType(typeBean);
                        // 通知房间列表页, 房间详情页刷新
                        loadDataSuccess(bean);
                        LiveDatabus.getInstance().with(Gobal.EVENT_KEY.REFESH_ROOM_DETAIL, Integer.class).postValue(1);
                        LiveDatabus.getInstance().with(Gobal.EVENT_KEY.REFESH_ROOM, Integer.class).postValue(1);
                    }

                    @Override
                    public void onFail(int errCode, String message) {
                    }
                });
            } else {
                // 创建模式, 创建按钮事件统一通知刷新
                viewModel.setRoomType(typeBean);
                if (!roomNameUserChanged) {
                    //创建模式, 如果用户已经修改了房间名,房间名称不再随类型变更变更, 没有修改则跟随设置成房间类型名称
                    viewModel.roomName.setValue(typeBean.getRoomName());
                }
            }

        } else if (requestCode == SaveModelActivity.REQUEST_CODE_SET_NAME) {
            if (null == data) {
                return;
            }
            String name = data.getStringExtra(SaveModelActivity.OPEN_MODE_ROOM_NAME);
            if (TextUtils.isEmpty(name)) {
                return;
            }
            roomNameUserChanged = true;
            viewModel.roomName.setValue(name);

        }
    }

//    private void changeFragment(Fragment fragment){
//        FragmentUtil.add(getActivity(), ((RoomAddActivity)getActivity()).getContentId(), fragment, this, true);
//    }

    @Override
    public void onResume() {
        super.onResume();
        ((RoomAddActivity) getActivity()).setTitle(getString(R.string.room_setting_room));
        ((RoomAddActivity) getActivity()).setRightTitle("");
    }

    public int getLayoutId() {
        return R.layout.room_fragment_setting;
    }

    @Override
    public int getBindingVariable() {
        return BR.data;
    }

    @Override
    protected RoomSettingInfoViewModel getViewModel() {
        BaseViewModelFactroy<RoomSetttingParentBean> myViewModelFactroy = new BaseViewModelFactroy<>(this, this);
        RoomSettingInfoViewModel tmp = new ViewModelProvider(this, myViewModelFactroy).get(RoomSettingInfoViewModel.class);
        if (editRoom != null) {
            tmp.initEditRoom = editRoom;
        }
        return tmp;
    }

    @Override
    protected void onRetryBtnClick() {
        showLoading();
        viewModel.onLoad();
    }

    /**
     * 设置紧急联系人
     *
     * @param person
     */
    public void setPerson(PersonSelectItemBean person) {
        if (!createMode) {
            // 编辑模式, 先提交后改变
            TimeZoneBean timeZoneBean = SystemUtil.getTimeZone();
            viewModel.setRoomEmergency(getActivity(), new RoomEmergencyBean(editRoom.getRoomUuid(), person.getEmergencyUuid(), timeZoneBean.getRoomTimeZone(), timeZoneBean.getRoomTimeZoneArea()),
                    new IOperationDetailResult<String>() {
                        @Override
                        public void onSuccess(String s) {
                            viewModel.setPerson(person);
                        }

                        @Override
                        public void onFail(int errCode, String message) {

                        }
                    });

        } else {
            // 创建模式, 由创建按钮统一通知变更事件通知
            viewModel.setPerson(person);
        }
    }

    /**
     * 设置受监护人
     *
     * @param ward
     */
    public void setWard(WardSelectItemBean ward) {
        if (!createMode) {
            // 编辑模式, 先提交后改变
            TimeZoneBean timeZoneBean = SystemUtil.getTimeZone();
            viewModel.setRoomWard(getActivity(), new RoomWardBean(ward.getWardUuid(), editRoom.getRoomUuid(), timeZoneBean.getRoomTimeZone(), timeZoneBean.getRoomTimeZoneArea()),
                    new IOperationDetailResult<String>() {
                        @Override
                        public void onSuccess(String s) {
                            viewModel.setWard(ward);
                            // 需要刷新 房间列表界面中的受监护人
                            LiveDatabus.getInstance().with(Gobal.EVENT_KEY.REFESH_ROOM, Integer.class).postValue(1);
                        }

                        @Override
                        public void onFail(int errCode, String message) {

                        }
                    });

        } else {
            // 创建模式, 由创建按钮统一通知变更事件通知
            viewModel.setWard(ward);
        }

    }

    @Override
    public void loadDataSuccess(RoomSetttingParentBean roomSetttingParentBean) {
        checkDevicesType(roomSetttingParentBean.getRadarInfo());
        functionSetInfo = roomSetttingParentBean.getFunctionSetInfo();
        roomSettingBean = roomSetttingParentBean.getRoomInfo();
        try {
            studyTime = Integer.parseInt(roomSetttingParentBean.getStudyTimeInfo().getStudyTimeSurplus());
        } catch (Exception e) {
            e.printStackTrace();
            LogUtils.d("学习天数转换异常");
        }
        viewModel.setEditRoomValue(getActivity(), roomSettingBean);
        viewDataBinding.roomFallSwitch.setChecked(roomSettingBean.getFallAlertSwitch() == 1);
        //viewModel.setRoomVipTips(functionSetInfo);
        //setVipFunViewOpenByRoomType(roomSettingBean.getRoomType());
        if (null != functionSetInfo) {
            //setVipFunViewBySwitch(functionSetInfo);
        }

        //顶部设备卡片
        radarInfoList = roomSetttingParentBean.getRadarInfo();
        if (radarInfoList != null && radarInfoList.size() > 0) {
            roomDeviceCardAdapter.setList(radarInfoList);
            String str = String.format(getString(R.string.room_devices_in_this_room), String.valueOf(radarInfoList.size()));
            viewDataBinding.roomTvCardTips.setText(str);
            viewDataBinding.roomDevicesCard.setVisibility(View.VISIBLE);
            viewDataBinding.roomVipFunList.setVisibility(View.VISIBLE);
        } else {
            viewDataBinding.roomDevicesCard.setVisibility(View.GONE);
            viewDataBinding.roomVipFunList.setVisibility(View.GONE);
        }

        initFunctionViewMap(functionSetInfo);
        //initFunctionDataMap();
        initVipFunction();
    }

    @Override
    public void loadDataFail(String decs) {
        showFailure(decs);
    }

    @Override
    public void loginStatusChanged() {

    }

    //检查设备列表中是否有指定种类的雷达
    private void checkDevicesType(List<RadarBean> radarList) {
        if (null == radarList || radarList.size() == 0) {
            viewModel.haveAssure.setValue(false);
            viewModel.haveWavve.setValue(false);
            return;
        }

        for (RadarBean radar : radarList) {
            if (null == radar) return;

            if (RadarType.ASSURE == radar.getType()) {
                viewModel.haveAssure.setValue(true);
            }
            if (RadarType.WAVVE == radar.getType()) {
                viewModel.haveWavve.setValue(true);
            }
        }
    }

    /**
     * 检测VIP 开关状态
     *
     * @param setBeans
     * @return
     */
    private boolean isFunViewVisibilityGone(List<RoomVipSetBean> setBeans) {
        if (null != setBeans && setBeans.size() > 0) {
            RoomVipSetBean bean = setBeans.get(0);
            if (null != bean && bean.serviceFunctionSwitch == 0) {
                // 开关开启状态
                return true;
            }
        }
        return false;

    }

    private void setVipFunViewOpenByRoomType(int roomType) {
        setVipFunViewGone();
        switch (roomType) {
            case 1:
                //外出未归
                viewDataBinding.roomOutNoBack.setIsShow(true);
                //行动能力分析
                viewDataBinding.roomTrendAnalysis.setIsShow(true);
                //久坐分析
                viewDataBinding.roomSedentaryAnalysis.setIsShow(true);
                //原地静止
                viewDataBinding.roomMotionlessAlert.setIsShow(true);
                viewDataBinding.roomTrendAnalysis.setShowUnderline(false);
                break;
            case 2:
                boolean haveAssure = viewModel.haveAssure.getValue();
                boolean haveWavve = viewModel.haveWavve.getValue();

                //起夜未归（离床未归）
                viewDataBinding.roomNightNoBack.setIsShow(true);
                //频繁起夜
                viewDataBinding.roomNightUpAnalysis.setIsShow(true);
                //卧床不起
                viewDataBinding.roomSleepTimeout.setIsShow(true);

                //有Assure而且没有Wavve 或者 两种雷达都有
                if ((haveAssure && !haveWavve) || (viewModel.haveAssure.getValue() && viewModel.haveWavve.getValue())) {
                    //外出未归
                    viewDataBinding.roomOutNoBack.setIsShow(true);
                    //行动能力分析
                    viewDataBinding.roomTrendAnalysis.setIsShow(true);
                    //作息异常
                    viewDataBinding.roomRegularLifestyle.setIsShow(true);
                    //久坐分析
                    viewDataBinding.roomSedentaryAnalysis.setIsShow(true);
                    //原地静止
                    viewDataBinding.roomMotionlessAlert.setIsShow(true);
                }

                if (haveAssure && haveWavve) {
                    viewDataBinding.roomTrendAnalysis.setShowUnderline(true);
                } else {
                    viewDataBinding.roomTrendAnalysis.setShowUnderline(false);
                }

                //只有Wavve时
                if (haveWavve) {
                    //心跳/呼吸骤停告警
                    viewDataBinding.roomNoVitalSignals.setIsShow(true);
                    //离床告警
                    viewDataBinding.roomBedExitWarning.setIsShow(true);
                    //作息异常
                    viewDataBinding.roomAbnormalSleep.setIsShow(true);
                }
                break;
            case 3:
                //外出未归
                viewDataBinding.roomOutNoBack.setIsShow(true);
                //频繁如厕
                viewDataBinding.roomBathroomUseAnalysis.setIsShow(true);
                //卫浴滞留
                viewDataBinding.roomBathroomDetention.setIsShow(true);
                //原地静止
                viewDataBinding.roomMotionlessAlert.setIsShow(true);
                viewDataBinding.roomTrendAnalysis.setShowUnderline(false);
                break;

            case 4:
                //行动能力分析
                viewDataBinding.roomTrendAnalysis.setIsShow(true);
                //用餐分析
                viewDataBinding.roomMealAnalysis.setIsShow(true);
                //久坐分析
                viewDataBinding.roomSedentaryAnalysis.setIsShow(true);
                //原地静止
                viewDataBinding.roomMotionlessAlert.setIsShow(true);
                viewDataBinding.roomTrendAnalysis.setShowUnderline(false);
                break;

            case 5:
                break;

            case 6:
                //行动能力分析
                viewDataBinding.roomTrendAnalysis.setIsShow(true);
                //久坐分析
                viewDataBinding.roomSedentaryAnalysis.setIsShow(true);
                //原地静止
                viewDataBinding.roomMotionlessAlert.setIsShow(true);
                viewDataBinding.roomTrendAnalysis.setShowUnderline(false);
                break;

            case 7:
                //行动能力分析
                viewDataBinding.roomTrendAnalysis.setIsShow(true);
                //原地静止
                viewDataBinding.roomMotionlessAlert.setIsShow(true);
                viewDataBinding.roomTrendAnalysis.setShowUnderline(false);
                break;
        }
    }

    private boolean isNoNull(List<RoomVipSetBean> beans) {
        if (null != beans && beans.size() > 0) {
            return true;

        } else {
            return false;
        }
    }

    private void setVipFunViewBySwitch(FunctionSetInfo functionSetInfo) {
        if (null == functionSetInfo) {
            return;
        }
        if (isFunViewVisibilityGone(functionSetInfo.getEgressNoReturn())) {
            //外出未归
            viewDataBinding.roomOutNoBack.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getToiletStop())) {
            //卫浴滞留
            viewDataBinding.roomBathroomDetention.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getHaveMeals())) {
            //用餐分析
            viewDataBinding.roomMealAnalysis.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getNightRiseNoReturn())) {
            //起夜未归
            viewDataBinding.roomNightNoBack.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getWorkAndRest())) {
            //作息规律
            viewDataBinding.roomRegularLifestyle.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getNightRise())) {
            //起夜分析
            viewDataBinding.roomNightUpAnalysis.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getToiletAnalysis())) {
            //频繁如厕
            viewDataBinding.roomBathroomUseAnalysis.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getSleepOvertime())) {
            //睡眠超时
            viewDataBinding.roomSleepTimeout.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getContinuitySit()) || isFunViewVisibilityGone(functionSetInfo.getAccumulateSit())) {
            //久坐分析
            viewDataBinding.roomSedentaryAnalysis.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getMotionlessAlert())) {
            //原地静止
            viewDataBinding.roomMotionlessAlert.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getTrendAnalysis())) {
            //行动能力分析
            viewDataBinding.roomTrendAnalysis.setIsShow(false);
        }

        if (isFunViewVisibilityGone(functionSetInfo.getNoVitalSignals())) {
            //心跳/呼吸骤停告警
            viewDataBinding.roomNoVitalSignals.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getBedExitWarning())) {
            //离床告警
            viewDataBinding.roomBedExitWarning.setIsShow(false);
        }
        if (isFunViewVisibilityGone(functionSetInfo.getAbnormalSleep())) {
            //作息异常
            viewDataBinding.roomAbnormalSleep.setIsShow(false);
        }

    }

    private void setVipFunViewGone() {
        //外出未归
        viewDataBinding.roomOutNoBack.setIsShow(false);
        //卫浴滞留
        viewDataBinding.roomBathroomDetention.setIsShow(false);
        //用餐分析
        viewDataBinding.roomMealAnalysis.setIsShow(false);
        //起夜未归
        viewDataBinding.roomNightNoBack.setIsShow(false);
        //作息规律
        viewDataBinding.roomRegularLifestyle.setIsShow(false);
        //起夜分析
        viewDataBinding.roomNightUpAnalysis.setIsShow(false);
        //频繁如厕
        viewDataBinding.roomBathroomUseAnalysis.setIsShow(false);
        //睡眠超时
        viewDataBinding.roomSleepTimeout.setIsShow(false);
        //久坐分析
        viewDataBinding.roomSedentaryAnalysis.setIsShow(false);
        //原地静止
        viewDataBinding.roomMotionlessAlert.setIsShow(false);
        //行动能力分析
        viewDataBinding.roomTrendAnalysis.setIsShow(false);

        //心跳/呼吸骤停告警
        viewDataBinding.roomNoVitalSignals.setIsShow(false);
        //离床告警
        viewDataBinding.roomBedExitWarning.setIsShow(false);
        //作息异常
        viewDataBinding.roomAbnormalSleep.setIsShow(false);
    }

    private static class DataBean {
        //离家模式、摔倒、功能设置
        View view;
        //功能设置对应的数据
        List<RoomVipSetBean> setBean;
        //累计久坐
        List<RoomVipSetBean> accumulateBean;

        public DataBean(View view) {
            this(view, null);
        }

        public DataBean(View view, List<RoomVipSetBean> setBean) {
            this(view, setBean, null);
        }

        public DataBean(View view, List<RoomVipSetBean> setBean, List<RoomVipSetBean> accumulateBean) {
            this.view = view;
            this.setBean = setBean;
            this.accumulateBean = accumulateBean;
        }
    }
}
